from django.test import TestCase

# Create your tests here.


def test_upload2():
    """
    """
    from biliup.plugins.bili_webup import BiliBili, Data

    video = Data()
    video.title = '王建硕:ERC20协议是什么'
    video.desc = 'ERC20协议是什么'
    video.source = 'YOUTUBE: PLzF5RwJfEo'
    # 设置视频分区,171手机游戏 181知识
    video.tid = 171
    video.set_tag(['ERC20'])
    with BiliBili(video) as bili:
        bili.login("bili.cookie", {
            'cookies': {
                'SESSDATA': 'ce03f5c6%2C1670495903%2Cd46bea61',
                'bili_jct': 'ba4908ae51a16c7433b69550c3b423ea',
                'DedeUserID__ckMd5': '880fb259feb25796',
                'DedeUserID': '326251800'
            }, 'access_token': '8d7cb4afd4ff4d4091559344580ba561'})
        # bili.login_by_password("18596761801", "")
        for file in ["../media/self/2022/06/30/V2022063014501656571846.mp4"]:
            video_part = bili.upload_file(file)  # 上传视频
            video.append(video_part)  # 添加已经上传的视频
        video.cover = bili.cover_up('../media/self/2022/06/30/V2022063015181656573501.png').replace('http:', '')
        ret = bili.submit()  # 提交视频


def test_upload():
    """
    https://www.bilibili.com/video/BV1c34y157BR#reply116446688688
    :return:
    """
    from biliup.plugins.bili_webup import BiliBili, Data

    video = Data()
    video.title = '初次投稿测试'
    video.desc = '录制时间：2022-06-11T14_02_51'
    video.source = '添加转载地址说明'
    # 设置视频分区,171手机游戏
    video.tid = 171
    video.set_tag(['pokemmo'])
    with BiliBili(video) as bili:
        bili.login("bili.cookie", {
            'cookies': {
                'SESSDATA': 'ce03f5c6%2C1670495903%2Cd46bea61',
                'bili_jct': 'ba4908ae51a16c7433b69550c3b423ea',
                'DedeUserID__ckMd5': '880fb259feb25796',
                'DedeUserID': '326251800'
            }, 'access_token': '8d7cb4afd4ff4d4091559344580ba561'})
        # bili.login_by_password("18596761801", "")
        for file in ["./bilibili_pokemon2022-06-11T14_02_51.mp4", "./test2022-06-11T15_33_45.webm",]:
            video_part = bili.upload_file(file)  # 上传视频
            video.append(video_part)  # 添加已经上传的视频
        video.cover = bili.cover_up('cover.png').replace('http:', '')
        ret = bili.submit()  # 提交视频


def test_download():
    from biliup.downloader import download

    # download("test", "https://www.youtube.com/watch?v=NhjKGfxVwTA")
    from biliup.plugins.youtube import Youtube

    download("bilibili_pokemon", "https://live.bilibili.com/16101?broadcast_type=0")
    # Youtube("test", "https://www.youtube.com/watch?v=660baZoWnoQ").start()


if __name__ == '__main__':
    # test_download()
    test_upload2()